package lzyc.pointsManagement.business.news.controller;

import lzyc.pointsManagement.business.news.domain.NewsInfo;
import lzyc.pointsManagement.business.news.service.NewsInfoService;
import lzyc.pointsManagement.common.core.domain.AjaxResult;
import lzyc.pointsManagement.common.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.*;
import lzyc.pointsManagement.common.core.controller.BaseController;

import javax.annotation.Resource;

import java.util.List;

import static lzyc.pointsManagement.common.utils.PageUtils.startPage;

/**
 * (NewsInfo)表控制层
 *
 * @author yangyang
 * @since 2024-03-10 17:10:20
 */
@RestController
@RequestMapping("/api/v1/news")
public class NewsInfoController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private NewsInfoService newsInfoService;

    /**
     * 获取支部动态
     *
     * @param count
     * @return
     */
    @PostMapping("/recent")
    @ResponseBody
    public AjaxResult recent(Integer count) {
        List<NewsInfo> list = newsInfoService.getNewsRecent(count);
        return AjaxResult.success(list);
    }

    /**
     * 分页获取动态列表
     *
     * @param newsInfo
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(NewsInfo newsInfo) {
        startPage();
        List<NewsInfo> list = newsInfoService.queryAll(newsInfo);
        return getDataTable(list);
    }

    /**
     * 获取支部动态通过ID
     *
     * @param newsID
     * @return
     */
    @PostMapping("/detail")
    @ResponseBody
    public AjaxResult detail(String newsID) {

        return AjaxResult.success(newsInfoService.queryById(newsID));
    }

    /**
     * 新增
     * 
     * @param newsInfo
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestBody NewsInfo newsInfo) {
        return toAjax(newsInfoService.insert(newsInfo));
    }

    /**
     * 修改
     * 
     * @param newsInfo
     * @return
     */
    @PostMapping("/update")
    @ResponseBody
    public AjaxResult update(@RequestBody NewsInfo newsInfo) {
        return toAjax(newsInfoService.update(newsInfo));
    }

    /**
     * 删除
     * 
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    @ResponseBody
    public AjaxResult delete(String ids) {
        return toAjax(newsInfoService.deleteById(ids));
    }

}